package com.d3works.apps.production.db.repo;

import com.d3works.apps.production.db.Machine;
import com.d3works.apps.production.db.MachineTool;
import com.d3works.apps.production.service.app.AppProductionService;
import com.google.inject.Inject;

public class MachineToolManagementRepository extends MachineRepository {

  @Inject MachineToolRepository machineToolRepository;
  @Inject AppProductionService appProductionService;

  @Override
  public Machine save(Machine entity) {
    if (appProductionService.getAppProduction().getEnableToolManagement()
        && entity.getMachineToolLineList() != null) {
      for (MachineTool machineTool : entity.getMachineToolLineList()) {
        machineTool.setMachine(entity);
        machineToolRepository.save(machineTool);
      }
    }
    return super.save(entity);
  }
}
